<?php

use Faker\Factory as Faker;
use App\Models\ChannelOrder;
use App\Repositories\ChannelOrderRepository;

trait MakeChannelOrderTrait
{
    /**
     * Create fake instance of ChannelOrder and save it in database
     *
     * @param array $channelOrderFields
     * @return ChannelOrder
     */
    public function makeChannelOrder($channelOrderFields = [])
    {
        /** @var ChannelOrderRepository $channelOrderRepo */
        $channelOrderRepo = App::make(ChannelOrderRepository::class);
        $theme = $this->fakeChannelOrderData($channelOrderFields);
        return $channelOrderRepo->create($theme);
    }

    /**
     * Get fake instance of ChannelOrder
     *
     * @param array $channelOrderFields
     * @return ChannelOrder
     */
    public function fakeChannelOrder($channelOrderFields = [])
    {
        return new ChannelOrder($this->fakeChannelOrderData($channelOrderFields));
    }

    /**
     * Get fake data of ChannelOrder
     *
     * @param array $postFields
     * @return array
     */
    public function fakeChannelOrderData($channelOrderFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'channel_id' => $fake->randomDigitNotNull,
            'house_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $channelOrderFields);
    }
}
